/**
 * 
 */
package boundary.components;

import java.awt.Container;
import java.io.File;

import javax.swing.JFileChooser;


/**
 * @author davide
 *
 */
public class QuadTreeFileSaver extends MyJFileChooser
{
    private static final long serialVersionUID = 1253558196265467032L;

    public QuadTreeFileSaver(File f)
    {
	super(1);
	this.setSelectedFile(this.replaceFileExtension(f));
    }

    @Override
    public boolean isValidSelection(Container parent)
    {
	return this.showDialog(parent, "Esporta") == JFileChooser.APPROVE_OPTION;
    }
    
    private File replaceFileExtension(File f)
    {
	int index;
	String fname = f.getName();
	
	index = fname.lastIndexOf('.');
	
	if(index > -1) {
	    fname = fname.substring(0, index) + ".qtr";
	}
	
	else {
	    fname += ".qtr";
	}
	
	return new File(fname);
    }
}
